package com.serverapk;

import android.app.Application;
import android.content.Context;
import android.hardware.usb.UsbManager;

import com.danikula.videocache.HttpProxyCacheServer;
import com.hcReader.Reader;
import com.serverapk.exceptionHandler.CrashHandler;
import com.serverapk.model.MyFileNameGenerator;
import com.serverapk.util.L;


public class BaseApplication extends Application {
    public static Context mContext;

    private static BaseApplication baseApplication;

    public static BaseApplication getInstance() {
        return baseApplication;
    }

    public UsbManager manager = null;
    public Reader reader = null;

    public final String url1 = "https://api.cake360.cn/card/geticpsd";
    public final String url2 = "https://api.cake360.cn/card/getstppwd";
    public final String url3 = "https://api.cake360.cn/card/cardinfo";


    public final String GUID = "AE01502D2BC029EF";
    public final String TOKEN = "RAVVQKgJKgegl-rvuhXJbSEWqaoLT2U2LCHk";

    public volatile boolean isCardOn = false;//是否插卡了
    public volatile boolean flag = false;
    public volatile boolean isVideo = true;//是否拍视频

    public volatile boolean isNotifySuc = true;

    public String lon;
    public String lat;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
        baseApplication = this;
        CrashHandler handler = CrashHandler.getInstance();
        handler.init(this);
    }

    private HttpProxyCacheServer proxy;

    public static HttpProxyCacheServer getProxy(Context context) {
        BaseApplication app = (BaseApplication) context.getApplicationContext();
        return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy;
    }

    private HttpProxyCacheServer newProxy() {
        return new HttpProxyCacheServer.Builder(this)
                .maxCacheSize(100 * 1024 * 1024)       // 100兆
                .fileNameGenerator(new MyFileNameGenerator())
                .build();
    }

    public void rebootAction() {
        L.e("MWindowService --- rebootAction");
        String cmd = "su -c reboot";
        try {
            Runtime.getRuntime().exec(cmd);
        } catch (Exception e) {
            L.e(" Fail to reboot:"+e.toString());
        }
    }
}
